package test3;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;

import model.Employee;
import model.Hotel;
import model.ListReservation;
import model.ListRoom;
import model.Reservation;

import org.junit.Assert;
import org.junit.Test;

public class HotelTest1 {
	@Test
	public void testLogout() {
		Hotel h = new Hotel();
		Employee empTest = new Employee(1, "A", "B", "ab", "123", 1);
		h.addEmployee(empTest);
		h.employeeLogin("ab", "123");
		Assert.assertEquals(h.getEmpOnline().getFirstname(),
				empTest.getFirstname());
		Assert.assertEquals(h.getEmpOnline().getLastname(),
				empTest.getLastname());
		Assert.assertEquals(h.getEmpOnline().getUsername(),
				empTest.getUsername());
		Assert.assertEquals(h.getEmpOnline().getPassword(),
				empTest.getPassword());
		Assert.assertEquals(h.getEmpOnline().getPosition(),
				empTest.getPosition());
		h.employeeLogout();
		Assert.assertEquals(h.getEmpOnline(), null);
	}

	@Test
	public void testDeleteRoom() {
		Hotel h = new Hotel();
		int check = 1;
		ListRoom listRoomTest = new ListRoom();
		h.addRoom("A", 1000, "12");
		h.addRoom("B", 1200, "12");
		h.addRoom("A", 1500, "23");
		h.addRoom("D", 1500, "13");

		h.deleteRoom(1);

		listRoomTest.addRoom("A", 1000, "12");
		listRoomTest.addRoom("A", 1500, "23");
		listRoomTest.addRoom("D", 1500, "13");
		if (h.getListRoom().getID() != listRoomTest.getID())
			check = 0;
		for (int i = 0; i <= listRoomTest.getID(); i++) {
			if (!h.getListRoom().getRoomByID(i)
					.equals(listRoomTest.getRoomByID(i)))
				check = 0;
		}
		Assert.assertEquals(check, 1);
	}

	@Test
	public void testSearchRoom() {
		Hotel h = new Hotel();
		int check = 1;
		ListRoom listRoomFound = new ListRoom();
		ListRoom listRoomTest = new ListRoom();
		h.addRoom("A", 1000, "12");
		h.addRoom("B", 1200, "12");
		h.addRoom("A", 1500, "23");

		listRoomFound = h.searchRoomByID(0);
		listRoomTest = new ListRoom();
		check = 1;
		listRoomTest.addRoom("A", 1000, "12");
		if (listRoomFound.getID() != listRoomTest.getID())
			check = 0;
		for (int i = 0; i <= listRoomFound.getID(); i++) {
			if (!listRoomFound.getRoomByID(i).equals(
					listRoomTest.getRoomByID(i)))
				check = 0;
		}
		Assert.assertEquals(check, 1);

		listRoomFound = h.searchRoomByType("A");
		listRoomTest = new ListRoom();
		check = 1;
		listRoomTest.addRoom("A", 1000, "12");
		listRoomTest.addRoom("A", 1500, "23");
		if (listRoomFound.getID() != listRoomTest.getID())
			check = 0;
		for (int i = 0; i <= listRoomFound.getID(); i++) {
			if (!listRoomFound.getRoomByID(i).equals(
					listRoomTest.getRoomByID(i)))
				check = 0;
		}
		Assert.assertEquals(check, 1);

		listRoomFound = h.searchRoomAvailable("C", 200, 3000);
		listRoomTest = new ListRoom();
		check = 1;
		if (listRoomFound.getID() != listRoomTest.getID())
			check = 0;
		Assert.assertEquals(check, 1);

		listRoomFound = h.searchRoomByPrice(900, 1300);
		listRoomTest = new ListRoom();
		check = 1;
		listRoomTest.addRoom("A", 1000, "12");
		listRoomTest.addRoom("B", 1200, "12");
		if (listRoomFound.getID() != listRoomTest.getID())
			check = 0;
		for (int i = 0; i <= listRoomFound.getID(); i++) {
			if (!listRoomFound.getRoomByID(i).equals(
					listRoomTest.getRoomByID(i)))
				check = 0;
		}

		Assert.assertEquals(check, 1);

	}

	@Test
	public void testmakeReservation() {
		Hotel h = new Hotel();
		int check = 1;
		ListReservation listTest = new ListReservation();
		h.addRoom("A", 1000, "12");
		h.addRoom("B", 1200, "12");
		h.addRoom("A", 1500, "23");

		Reservation reser = new Reservation(0, 2, 2, null, null, 0, null, 0);
		h.make_reservationTest(reser);
		listTest.addreservation(0, 2, 2, null, null, 0, null, 0);
		if (!h.getListReservation().search_reservation(0)
				.equals(listTest.search_reservation(0)))
			check = 0;
		Assert.assertEquals(check, 1);
	}

	@Test
	public void testcancelReservation() {
		Hotel h = new Hotel();
		int check = 1;
		ListReservation listTest = new ListReservation();
		h.addRoom("A", 1000, "12");
		h.addRoom("B", 1200, "12");
		h.addRoom("A", 1500, "23");

		Reservation reser = new Reservation(0, 2, 2, null, null, 0, null, 0);
		h.make_reservationTest(reser);
		h.make_reservation(1, 2, 1, null, null, 0, null, 0);
		h.cancel_reservation(1);
		listTest.addreservation(0, 2, 2, null, null, 0, null, 0);
		if (!h.getListReservation().search_reservation(0)
				.equals(listTest.search_reservation(0)))
			check = 0;
		Assert.assertEquals(check, 1);
	}

	@Test
	public void testCheckin() throws ParseException {
		Hotel h = new Hotel();
		h.addRoom("A", 1000, "12");
		h.addRoom("B", 1200, "12");
		h.addRoom("A", 1500, "23");

		Reservation reser = new Reservation(0, 2, 2, null, null, 0, null, 0);
		h.make_reservationTest(reser);
		h.make_reservation(1, 2, 1, null, null, 0, null, 0);

		h.check_in(2, 1, 0);
		Assert.assertEquals(h.getListRoom().getRoomByID(1).getStatus(), 2);

		h.check_out(2, 1, 0);

		Assert.assertEquals(h.getListRoom().getRoomByID(1).getStatus(), 0);
	}
}
